//
//  CSSVisitorTableViewController.swift
//  weibo28
//
//  Created by chushushan on 16/5/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CSSVisitorTableViewController: UITableViewController {

    //用户是否登录的标识
    var userLogin = CSSUserAccountViewModel.shareUserAccount.isLogin
    //自定义的访客视图
    var visitorView: CSSVisitorView?
    
    override func loadView() {
        
        if userLogin {
        
        super.loadView()
            
        } else {
        
            //没有登录的情况下，我们需要提供自定义的访客视图
            visitorView = CSSVisitorView()
            
            visitorView!.callBackClosure = { [weak self] in
            
                self?.requestOAuthLogin()
//                print("通过闭包让控制器响应点击事件")
            
            }
            
            view = visitorView
            
            //创建按钮
            setupNavUI()
            
        }
        
    }
    
    
    //设置导航栏按钮
       private func setupNavUI() {
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", fontSize: 15, target: self, action: "loginAction")
    
    }
    
    
    //注册的点击事件
    @objc private func registerAction() {
    
//    print("注册")
        requestOAuthLogin()
    }
    //登录按钮点击事件
    @objc private func loginAction() {
    
        requestOAuthLogin()
//    print("登录")
    }
    
    
    //跳转三方登录页面
    private func requestOAuthLogin() {
    
        let oauthVC = CSSOAuthViewController()
        
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
    
    }
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
       
    }

  

}
